package com.alibaba.dubbo.consumer;

import com.alibaba.dubbo.demo.DemoService;
import com.alibaba.dubbo.demo.HelloService;
import com.alibaba.fastjson.JSONObject;

import java.util.Map;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Consumer {
    public static void main(String[] args) {
        //测试常规服务
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("consumer.xml");
        context.start();
        System.out.println("consumer start");
        // Get Servise By Type
        DemoService demoService = context.getBean(DemoService.class);
        System.out.println("consumer");
        System.out.println(demoService.getPermissions(19L));
        
        // Get Service By Name
         DemoService service = (DemoService)context.getBean("permissionService");
         System.out.println("consumer consume");
         System.out.println(JSONObject.toJSONString(service.getPermissions(19L)));
         Map<String, String> info = service.listInfos("Hello");
         System.out.println("Infos" + JSONObject.toJSONString(info));
        
         //Get another Service
         HelloService helloService = (HelloService)context.getBean("helloService");
         String msg = helloService.greet("Lily");
         System.out.println("MSG:" + msg);
    }
}
